import {axios} from "../../utils/request"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight:"",
    navBarHeight:"",
    openId:"",
    initData:{},
    isStart:false
  },
  back(){
    wx.navigateBack({
      delta: 1
    })
  },
  async satrt(){
    const isStart = this.data.isStart
    const { id } = this.data.initData as any
    const isLogin = wx.getStorageSync('isLogin')
    if(isLogin){
      if(isStart){
        await axios('/start/remove',"POST",{id})
        this.setData({
          isStart:false
        })
      }else{
        await axios('/start',"POST",{id})
        this.setData({
          isStart:true
        })
      }
    }else{
      wx.navigateTo({
        url:"/pages/login/login"
      }) 
    }
   
  },
  /**
   * 生命周期函数--监听页面加载
  */
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('contextData', ({data,isStart})=> {
        this.setData({
          initData:data,
          isStart
        })
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const statusBarHeight = wx.getStorageSync("statusBarHeight");
    const navBarHeight = wx.getStorageSync("navBarHeight");
    this.setData({
      statusBarHeight,
      navBarHeight
    })
  }
})